# 方法1-直接求和
def sumtest01(num1):
    i = 0
    sum = 0
    while i < num1:
        sum += i
        i += 1
    print(sum)
    
sumtest01(123)

# 方法2-通过列表求和
def sumtest11(num):
    count = 0
    jishu = []
    sum = 0
    while count < num:
        count += 1
        jishu.append(count)
    print(jishu)    
    
    for i in jishu:
        sum += i
    print(sum)
        
sumtest11(6)
# [1, 2, 3, 4, 5, 6]
# 21

# 方法4-range循环
def sumtest02(num2):
    sum = 0
    for i in range(num2):
        sum = sum+ i 
    print(sum)
    
sumtest02(123)

# 从a加到b
def sumtest03(a,b):
    count = a-1
    jishu = []
    sum = 0
    while count < b:
        count += 1
        jishu.append(count)
        
    for i in jishu:
        sum +=i
    print(sum)
    
sumtest03(2,4)
# 9

# *使得出入的数据(args)自动变成一个元组,这样传入的参数可以是混合型的
def post_name(*args):
    toping = args
    return toping

post_name("mai","feng","yuan",1,['dio',"jojo"])
#('mai', 'feng', 'yuan', 1, ['dio', 'jojo'])

# **kwargs,把关键字参数转化为字典
def infos(**kwargs):
    print(kwargs)
    
infos(name="Maify",age="20",job="senior")
# {'name': 'Maify', 'age': '20', 'job': 'senior'}

# 结合空列表与空字典制作一个字典的存储器，函数调用只是负责输入（局部变量和全局变量）
a = []
def info_m(** kwargs):
    a.append(kwargs)
    return a

info_m(name="Maify",age="20",job="senior")
# [{'name': 'Maify', 'age': '20', 'job': 'senior'}]
info_m(name="jack",age="19",job="freshman")
# [{'name': 'Maify', 'age': '20', 'job': 'senior'},
#  {'name': 'jack', 'age': '19', 'job': 'freshman'}]